package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zyg.pojo.Clas;
import com.zyg.pojo.Grade;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface ClasMapper extends BaseMapper<Clas> {
    // 根据 entity 条件，查询全部记录
    @Override
    @Select("select clas_id,clas_name,grade_id from sys_clas")//一定要特别注意@One注解的使用，使用了@one就不用写连接表的sql语句
    @Results(id="clasMap", value = {
            @Result(property="clasId",column="clas_id"),
            @Result(property="clasName",column="clas_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    List<Clas> selectList(IPage<Clas> page, Wrapper<Clas> wrapper);
    @Override
    @Select("select * from sys_clas where clas_id=#{clasId}")
    @Results(id="clasMap1", value = {
            @Result(property="clasId",column="clas_id"),
            @Result(property="clasName",column="clas_name"),
            @Result(property="grade",column="grade_id",javaType= Grade.class,
                    one=@One(select="com.zyg.dao.GradeMapper.selectById",fetchType = FetchType.LAZY )),

    })
    Clas selectById(Serializable clasId);
}

